package com.scuec.groupfive.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scuec.groupfive.entity.PastExam;
import com.scuec.groupfive.mapper.PastExamMapper;
import com.scuec.groupfive.service.PastExamService;
import com.scuec.groupfive.vo.PastExamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class PastExamServiceImpl implements PastExamService {

    @Autowired
    private PastExamMapper pastExamMapper;

    @Override
    public PageInfo<PastExam> getPastExamPages(Integer pageNum, Integer pageSize) {
        // 启动分页
        PageHelper.startPage(pageNum, pageSize);
        // 查询所有考试记录
        List<PastExam> pastExams = pastExamMapper.getAllPastExams();
        // 返回分页信息
        return new PageInfo<>(pastExams);
    }

    @Override
    public PageInfo<PastExamVO> getPastExamByUsername(String username, Integer pageNum, Integer pageSize) {
        // 启动分页
        PageHelper.startPage(pageNum, pageSize);
        // 根据用户名查询考试记录
        List<PastExamVO> pastExams = pastExamMapper.getPastExamsByUsername(username);
        // 返回分页信息
        return new PageInfo<>(pastExams);
    }

    @Override
    public Map<String, Object> getExamStatsByUsername(String username) {
        return pastExamMapper.getExamStatsByUsername(username);
    }
}